package com.sx.zongzhi.adapter;


import android.content.Context;
import android.support.annotation.LayoutRes;
import android.support.annotation.Nullable;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.sx.zongzhi.R;
import com.sx.zongzhi.bean.AppealTypeBean;
import com.sx.zongzhi.widget.NoScrollGridView;

import java.util.List;

/**
 * Created by XZY on 2017/12/4.
 * 诉求服务类型选择的adapter
 */

public class AppealTypeSelectAdapter extends BaseQuickAdapter<AppealTypeBean,BaseViewHolder> {

    private Context context;
    EventTypeCallback mCallback;

    public AppealTypeSelectAdapter(Context context, @LayoutRes int layoutResId, @Nullable List<AppealTypeBean> data) {
        super(layoutResId, data);
        this.context=context;
    }

    @Override
    protected void convert(BaseViewHolder helper, final AppealTypeBean item) {
        helper.setText(R.id.tv_Title,item.getDomainName());
        NoScrollGridView gridView=helper.getView(R.id.gridView);
        if (item.getRows()!=null&&item.getRows().size()>0) {
            AppealTypeListAdapter adapter = new AppealTypeListAdapter(context, R.layout.item_event_type_list, item.getRows());
            gridView.setAdapter(adapter);
            adapter.getEventType(new AppealTypeListAdapter.EventTypeCallback() {
                @Override
                public void getData(AppealTypeBean.RowsBean rowsBean) {
                    if (mCallback!=null){
                        mCallback.getData(rowsBean,item.getDomainName());
                    }
                }
            });
        }
    }

    /**
     * 定义一个接口
     */
    public interface EventTypeCallback {
        void getData(AppealTypeBean.RowsBean typesBean, String prentName);
    }

    /*接口回调*/
    public void getTypeData(EventTypeCallback callback) {
        mCallback = callback;
    }
}
